var ServiceFacade;
(function (ServiceFacade) {
    (function (Utilities) {
        var Arr = (function () {
            function Arr() {
            }
            Arr.Equals = function (first, second) {
                // if the other array is a falsy value, return
                if (!second)
                    return false;

                // compare lengths - can save a lot of time
                if (first.length != second.length)
                    return false;

                for (var i = 0, l = first.length; i < l; i++) {
                    // Check if we have nested arrays
                    if (first[i] instanceof Array && second[i] instanceof Array) {
                        // recurse into the nested arrays
                        if (!this.Equals(first[i], second[i]))
                            return false;
                    } else if (first[i] != second[i]) {
                        // Warning - two different object instances will never be equal: {x:20} != {x:20}
                        return false;
                    }
                }
                return true;
            };
            return Arr;
        })();
        Utilities.Arr = Arr;
    })(ServiceFacade.Utilities || (ServiceFacade.Utilities = {}));
    var Utilities = ServiceFacade.Utilities;

    (function (Core) {
        var AjaxCall = (function () {
            function AjaxCall() {
                var xhr;
                if (typeof XMLHttpRequest !== 'undefined') {
                    xhr = new XMLHttpRequest();
                } else {
                    var versions = [
                        "MSXML2.XmlHttp.5.0",
                        "MSXML2.XmlHttp.4.0",
                        "MSXML2.XmlHttp.3.0",
                        "MSXML2.XmlHttp.2.0",
                        "Microsoft.XmlHttp"
                    ];
                    for (var i = 0; i < versions.length; i++) {
                        try  {
                            xhr = new ActiveXObject(versions[i]);
                            break;
                        } catch (e) {
                            // swallow the exception
                        }
                    }
                }
                this.xhr = xhr;
            }
            AjaxCall.prototype.send = function (url, callback, method, data) {
                var _this = this;
                this.xhr.open(method, url, false);
                this.xhr.onreadystatechange = function () {
                    if (_this.xhr.readyState == XMLHttpRequest.DONE) {
                        var success = false;
                        if (_this.xhr.status == 200) {
                            success = true;
                        }
                        callback(success, _this.xhr.responseText);
                    }
                };
                if (method == 'POST') {
                    this.xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
                }
                this.xhr.send(data);
            };

            AjaxCall.prototype.post = function (url, data, callback) {
                var query = JSON.stringify(data);
                this.send(url, callback, 'POST', query);
            };

            AjaxCall.prototype.dispose = function () {
                this.xhr = null;
            };
            return AjaxCall;
        })();

        var Service = (function () {
            function Service() {
            }
            Service.Call = function (endPoint, postData, responseHandler, ctor) {
                var call = new AjaxCall();
                call.post(endPoint, postData, function (success, responseData) {
                    call.dispose();
                    if (success) {
                        var response = JSON.parse(responseData);
                        var returnObject = response.d;
                        if (ctor != null) {
                            returnObject = new ctor(returnObject);
                        }
                        responseHandler(returnObject);
                    } else {
                        throw Error("Service call failed with error: " + responseData);
                    }
                });
            };
            return Service;
        })();
        Core.Service = Service;
    })(ServiceFacade.Core || (ServiceFacade.Core = {}));
    var Core = ServiceFacade.Core;

    var FractionService = (function () {
        function FractionService() {
        }
        FractionService.ConvertFractionToDecimal = function (fraction, callback) {
            ServiceFacade.Core.Service.Call("Services/FractionService.asmx/ConvertFractionToDecimal", {
                'fraction': fraction
            }, callback, null);
        };

        FractionService.ConvertDecimalToFraction = function (number, callback) {
            ServiceFacade.Core.Service.Call("Services/FractionService.asmx/ConvertDecimalToFraction", {
                'number': number
            }, callback, Muel.TypeScriptFacade.TestPlatform.Services.Fraction);
        };
        return FractionService;
    })();
    ServiceFacade.FractionService = FractionService;
    ;
})(ServiceFacade || (ServiceFacade = {}));
var Muel;
(function (Muel) {
    (function (TypeScriptFacade) {
        (function (TestPlatform) {
            (function (Services) {
                var Fraction = (function () {
                    function Fraction(data) {
                        this.__type = "Muel.TypeScriptFacade.TestPlatform.Services.Fraction";
                        if (data == null) {
                            return;
                        }
                        this.Numerator = data.Numerator;
                        this.Denominator = data.Denominator;
                    }
                    Fraction.prototype.snapshot = function () {
                        this._Numerator = this.Numerator;
                        this._Denominator = this.Denominator;
                    };

                    Fraction.prototype.hasChanges = function () {
                        if (this._Numerator != this.Numerator) {
                            return true;
                        }
                        if (this._Denominator != this.Denominator) {
                            return true;
                        }
                        return false;
                    };
                    return Fraction;
                })();
                Services.Fraction = Fraction;
            })(TestPlatform.Services || (TestPlatform.Services = {}));
            var Services = TestPlatform.Services;
        })(TypeScriptFacade.TestPlatform || (TypeScriptFacade.TestPlatform = {}));
        var TestPlatform = TypeScriptFacade.TestPlatform;
    })(Muel.TypeScriptFacade || (Muel.TypeScriptFacade = {}));
    var TypeScriptFacade = Muel.TypeScriptFacade;
})(Muel || (Muel = {}));
//# sourceMappingURL=ServiceFacade.js.map
